package com.spy.material.service.impl;

import java.util.List;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.spy.common.utils.DateUtils;
import com.spy.material.dto.InventoryDetailQueryDTO;
import com.spy.material.vo.InventoryDetailPageVO;
import com.spy.material.vo.InventoryDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.spy.material.mapper.InventoryDetailMapper;
import com.spy.material.domain.InventoryDetail;
import com.spy.material.service.IInventoryDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Arrays;
/**
 * 库存明细Service业务层处理
 * 
 * @author twc
 * @date 2025-11-09
 */
@Service
public class InventoryDetailServiceImpl extends ServiceImpl<InventoryDetailMapper, InventoryDetail> implements IInventoryDetailService
{
    @Autowired
    private InventoryDetailMapper inventoryDetailMapper;

    /**
     * 查询库存明细
     * 
     * @param id 库存明细主键
     * @return 库存明细
     */
    @Override
    public InventoryDetail selectInventoryDetailById(Long id)
    {
                return getById(id);
    }

    /**
     * 查询库存明细列表
     * 
     * @param inventoryDetail 库存明细
     * @return 库存明细
     */
    @Override
    public List<InventoryDetail> selectInventoryDetailList(InventoryDetail inventoryDetail)
    {
        return inventoryDetailMapper.selectInventoryDetailList(inventoryDetail);
    }

    /**
     * 新增库存明细
     * 
     * @param inventoryDetail 库存明细
     * @return 结果
     */
    @Override
    public int insertInventoryDetail(InventoryDetail inventoryDetail)
    {
        inventoryDetail.setCreateTime(DateUtils.getNowDate());
                return save(inventoryDetail) ? 1 : 0;
    }

    /**
     * 修改库存明细
     * 
     * @param inventoryDetail 库存明细
     * @return 结果
     */
    @Override
    public int updateInventoryDetail(InventoryDetail inventoryDetail)
    {
        inventoryDetail.setUpdateTime(DateUtils.getNowDate());
                return updateById(inventoryDetail) ? 1 : 0;
    }

    /**
     * 批量删除库存明细
     * 
     * @param ids 需要删除的库存明细主键
     * @return 结果
     */
    @Override
    public int deleteInventoryDetailByIds(Long[] ids)
    {
                return removeByIds(Arrays.asList(ids)) ? 1 : 0;
    }

    /**
     * 删除库存明细信息
     * 
     * @param id 库存明细主键
     * @return 结果
     */
    @Override
    public int deleteInventoryDetailById(Long id)
    {
                return removeById(id) ? 1 : 0;
    }

    @Override
    public InventoryDetailPageVO all(InventoryDetailQueryDTO inventoryDetailQueryDTO) {
        PageHelper.startPage(inventoryDetailQueryDTO.getPage(), inventoryDetailQueryDTO.getPageSize());
        Page<InventoryDetailVO> page = inventoryDetailMapper.all(inventoryDetailQueryDTO);
        InventoryDetailPageVO inventoryDetailPageVO = new InventoryDetailPageVO();
        inventoryDetailPageVO.setTotal(page.getTotal());
        inventoryDetailPageVO.setRows(page.getResult());
        return inventoryDetailPageVO;
    }
}
